package com.jse.util.internationalization;

import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;

import org.junit.Test;

public class I18NTest {
	
	@Test
	public void testSimple() {
		Locale local = Locale.CHINESE;
//		Locale local = new Locale("zh");
		ResourceBundle bundle = ResourceBundle.getBundle("myBundle", local);
		System.out.println(bundle.getString("farewell"));
	}
	
	/**
	 * 如果国际化资源文件在类目录，baseName=包名+资源文件名
	 * 参考：org.apache.tomcat.util.res.StringManager
	 */
	@Test
	public void testPathResource() {
//		PropertyResourceBundle bundle = new PropertyResourceBundle();
		Locale local = Locale.CHINESE;
		ResourceBundle bundle = ResourceBundle.getBundle("com.jse.util.internationalization.Source", local);
		System.out.println(bundle.getString("farewell"));
	}
	
	/**
	 * 资源中使用占位符
	 */
	@Test
	public void testPlaceholder() {
		Locale local = Locale.CHINESE;
		ResourceBundle bundle = ResourceBundle.getBundle("com.jse.util.internationalization.Placeholder", local);
		String msg = bundle.getString("hello");
		String m1 = MessageFormat.format(msg, "好", "java");
		System.out.println(m1);
		
		System.out.println("========");
		MessageFormat mf = new MessageFormat(msg);
		StringBuffer m2 = mf.format(new String[]{"很好", "c"}, new StringBuffer(), null);
		System.out.println(m2.toString());
		
		System.out.println("=========");
		MessageFormat mf1 = new MessageFormat("{0},{0},{0}");
		StringBuffer m3 = mf1.format(new String[]{"1", "2"}, new StringBuffer(), null);
		System.out.println(m3);
	}
	
	/**
	 * 参考http://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html
	 */
	public void testCustomizing() {
		
	}
}
